package com.magneticattraction.service;

import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import androidx.annotation.Nullable;

public class ReceiveAndSendService extends Service {
    private static final String TAG = "ReceiveAndSendService";

    public ReceiveAndSendService() {
    }

    @Override
    public IBinder onBind(Intent intent) {

        return iBinder;
        //return null;

    }

    @Override
    public boolean onUnbind(Intent intent) {
        return super.onUnbind(intent);
    }

    @Override
    public void sendBroadcast(Intent intent) {
        super.sendBroadcast(intent);
    }


    @Override
    public void onCreate() {
        super.onCreate();
        // 发送广播
        Boolean sensor_data = getSensorData();
        Intent intent = new Intent();
        intent.putExtra("sensor", sensor_data);
        intent.setComponent(new ComponentName(getPackageName(), "com.magneticattraction.testnfc.SensorReceiver.class"));//显示指定组件名称
        sendBroadcast(intent);
        System.out.println("ReceiveAndSendService: 发送广播");
        Log.d(TAG, "onCreate: 发送广播");

    }


    private IBinder iBinder = new OpenOrCloseAidlInterface.Stub() {
        @Override
        public boolean openOrClose(int status) throws RemoteException {
            //实现一个io流，往里面写

            return false;
        }
    };


    private IBinder iBinder1 = new ReadNodeAidlInterface.Stub() {
        @Override
        public boolean ReadNode() throws RemoteException {
            //读取状态，1返回true/
            return false;
        }
    };


    //获取Sensor数据
    public Boolean getSensorData() {
        return true;
    }


}